package com.jsoft.pds.view.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

@XStreamAlias("PanelMenu")
public class Menu implements Serializable{

	private static final long serialVersionUID = 4728348622357188999L;
	
	public static final String ALL_PRIVILEGES = "@all";
	public static final String URL_MENU =  "xml/menu/menu-config.xml";
	
	@XStreamAsAttribute
	private String homeAdmin;
	
	@XStreamAsAttribute
	private String homeRecepcion;
	
	@XStreamAsAttribute
	private String homeCaja;
	
	@XStreamImplicit
	private List<SubMenu> subMenu;
	
	public Menu(){
		super();
		subMenu = new ArrayList<SubMenu>();
	}
	
	public boolean isEmpty(){
		return (subMenu == null || subMenu.size() == 0);
	}
	
	public String getHomeAdmin() {
		return homeAdmin;
	}
	public void setHomeAdmin(String homeAdmin) {
		this.homeAdmin = homeAdmin;
	}
	public String getHomeRecepcion() {
		return homeRecepcion;
	}
	public void setHomeRecepcion(String homeRecepcion) {
		this.homeRecepcion = homeRecepcion;
	}
	public String getHomeCaja() {
		return homeCaja;
	}
	public void setHomeCaja(String homeCaja) {
		this.homeCaja = homeCaja;
	}

	public List<SubMenu> getSubMenu() {
		return subMenu;
	}
	public void setSubMenu(List<SubMenu> subMenu) {
		this.subMenu = subMenu;
	}

	/** CLASS SUBMENU_CUSTOM **/
	
	@XStreamAlias("SubMenu")
	public class SubMenu implements Serializable{
		
		private static final long serialVersionUID = 1L;

		@XStreamAsAttribute
		private String name;
		
		@XStreamAsAttribute
		private String label;
		
		@XStreamAsAttribute
		private String profile;
		
		@XStreamAsAttribute
		private String image;
		
		@XStreamImplicit
		List<MenuItem> menuItem;
		
		public SubMenu(){
			super();
			menuItem = new ArrayList<MenuItem>();
		}
		
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public String getLabel() {
			return label;
		}
		public void setLabel(String label) {
			this.label = label;
		}
		public String getProfile() {
			return profile;
		}
		public void setProfile(String profile) {
			this.profile = profile;
		}
		public String getImage() {
			return image;
		}
		public void setImage(String image) {
			this.image = image;
		}
		public List<MenuItem> getMenuItem() {
			return menuItem;
		}
		public void setMenuItem(List<MenuItem> menuItem) {
			this.menuItem = menuItem;
		}
		public boolean allPrivileges(){
			return (profile != null ? profile.equals(ALL_PRIVILEGES) : false);
		}
		public boolean isMenuItemEmpty(){
			return (getMenuItem() != null ? getMenuItem().size() == 0 : true);
		}
	}
	
	/** CLASS SUBMENUITEM_CUSTOM **/
	@XStreamAlias("MenuItem")
	public class MenuItem implements Serializable{
		
		private static final long serialVersionUID = -661648839690028254L;

		@XStreamAsAttribute
		private String name;
		
		@XStreamAsAttribute
		private String label;
		
		@XStreamAsAttribute
		private String page;
		
		@XStreamAsAttribute
		private String profile;
		
		@XStreamAsAttribute
		private String image;
		
		public MenuItem(){
			super();
		}

		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public String getLabel() {
			return label;
		}
		public void setLabel(String label) {
			this.label = label;
		}
		public String getPage() {
			return page;
		}
		public void setPage(String page) {
			this.page = page;
		}
		public String getProfile() {
			return profile;
		}
		public void setProfile(String profile) {
			this.profile = profile;
		}
		public String getImage() {
			return image;
		}
		public void setImage(String image) {
			this.image = image;
		}
		public boolean allPrivileges(){
			return (profile != null ? profile.equals(ALL_PRIVILEGES) : false);
		}
		
	}
}
